/**
 * Project Name:dsrs-systemservice-service
 * File Name:UserLevelServiceImpl.java
 * Package Name:com.bwda.dsrs.systemservice.service.impl;
 * Date:2019年4月28日
 * Copyright (c) 2019, 江苏保旺达软件有限公司 All Rights Reserved.
 */
package com.bwda.dsrs.systemservice.service.impl;

import com.bwda.dsrs.base.centerbase.util.PageHelperUtil;
import com.bwda.dsrs.systemservice.domain.Constants;
import com.bwda.dsrs.systemservice.domain.condition.userlevel.UserLevelCondition;
import com.bwda.dsrs.systemservice.domain.exception.SystemServiceException;
import com.bwda.dsrs.systemservice.domain.po.userlevel.UserLevelPo;
import com.bwda.dsrs.systemservice.mapper.UserLevelMapper;
import com.bwda.dsrs.systemservice.service.UserLevelService;
import com.github.pagehelper.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户等级
 *
 * @author liangjianyong
 * @date 2019/4/22
 */
@Service
public class UserLevelServiceImpl extends AbstractBaseServiceImpl<UserLevelPo, UserLevelCondition, UserLevelMapper> implements UserLevelService {

    @Override
    public void insert(UserLevelPo po) {
        po.setDelFlag(Constants.NOT_DELETED);
        po.setStatus(Constants.StateType.ENABLE);
        super.insert(po);
    }

    @Override
    public int update(UserLevelPo po) {
        po.setDelFlag(Constants.NOT_DELETED);
        return super.update(po);
    }

    @Override
    public void updateWithValid(UserLevelPo po)
        throws SystemServiceException {
        po.setDelFlag(Constants.NOT_DELETED);
        super.updateWithValid(po);
    }

    @Override
    public int queryCount(UserLevelCondition condition) {
        condition.setDelFlag(Constants.NOT_DELETED);
        return super.queryCount(condition);
    }

    @Override
    public List<UserLevelPo> queryList(UserLevelCondition condition) {
        condition.setDelFlag(Constants.NOT_DELETED);
        return super.queryList(condition);
    }

    @Override
    public void delete(Object id)
        throws SystemServiceException {
        UserLevelPo po=new UserLevelPo();
        po.setId((Integer)id);
        po.setDelFlag(Constants.DELETED);
        this.getMapper().update(po);
    }

    /**
     * 根据类型查询用户分级列表
     * @param levelType
     * @return
     */
    @Override
    public List<UserLevelPo> queryUserLevelByLevelType(String levelType){
        if(StringUtils.isBlank(levelType)){
            return new ArrayList<UserLevelPo>();
        }
        UserLevelCondition condition=new UserLevelCondition();
        condition.setDelFlag(Constants.NOT_DELETED);
        condition.setStatus(Constants.StateType.ENABLE);
        condition.setLevelType(levelType);
        return this.getMapper().selectList(condition);
    }

    @Override
    public List<UserLevelPo> queryListWithTypeName(UserLevelCondition condition) {
        PageHelperUtil.startPage(condition.getPageNum(), condition.getPageSize());
        List<UserLevelPo> list = this.getMapper().selectListWithTypeName(condition);
        return list;
    }

    @Override
    public int countIsExist(UserLevelCondition userLevelCondition) {
        return this.getMapper().countIsExist(userLevelCondition);
    }

    @Override
    public void batchDelete(List<Integer> idList) {
        UserLevelPo po = new UserLevelPo();
        po.setIdList(idList);
        po.setDelFlag(Constants.DELETED);
        this.getMapper().update(po);
    }

}